package cn.gx.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 数据工具类
 * @author always
 *
 */
public class DataUtil {
	/**
	 * 采用Md5加密
	 * @param src
	 * @return
	 */
	public static String md5(String src){
		try {
			
			StringBuffer buffer=new StringBuffer();
			char [] chars={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] target = md.digest(src.getBytes());//16
			
			for(byte b:target){//16*2
				//System.out.println("字节b:"+b);
				//高4位
				buffer.append(chars[b>>4&0x0F]);
				//低4位
				buffer.append(chars[b&0x0F]);
			}
			return buffer.toString();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return null;
	}
}
